package pl.register.android.database.crud;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import pl.register.android.database.tables.StudentInGroupsDBTable;
import pl.register.android.group.StudentsGroup;
import pl.register.android.student.Student;
import pl.register.android.year.Year;

/**
 * @author Mateusz Strzelecki
 * @since 2013-04-26
 */
public class StudentInGroupCRUD {

    private SQLiteDatabase database;

    public StudentInGroupCRUD(SQLiteDatabase database) {
        this.database = database;
    }

    public void insert(Student student, StudentsGroup group) {
        ContentValues insertValues = new ContentValues();
        insertValues.put(StudentInGroupsDBTable.FK_GROUP_ID, group.getId());
        insertValues.put(StudentInGroupsDBTable.FK_STUDENT_ID, student.getId());
        long idRow = database.insert(StudentInGroupsDBTable.TABLE_NAME, null, insertValues);
    }

    public void delete(Student student, StudentsGroup group) {
        String where = StudentInGroupsDBTable.FK_STUDENT_ID + " = " + student.getId()
                + " AND " +
                StudentInGroupsDBTable.FK_GROUP_ID + " = " + group.getId();
        int res = database.delete(StudentInGroupsDBTable.TABLE_NAME, where, null);
    }

}
